import { computed } from 'vue'
import type { Ref, WritableComputedRef } from 'vue'

export const useBillListSelectAll = (billList: Ref<{ checked: boolean }[]>, fn:Function): { selectAll: WritableComputedRef<boolean>} => {
	const selectAll = computed({
		get () {
			if (billList.value.length === 0) {
				return false
			}
			return billList.value.every((item: { checked: boolean }) => item.checked)
		},
		set (val:boolean) {
			fn(val)
		}
	})
	return {
		selectAll
	}
}
